$(function() {
	jQuery.validator.addMethod("isphone", function(value, element) {   
		return this.optional(element) || /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test(value);   
	}, "请正确填写您的手机号码");
	
	$("#regist_form").validate({
		errorPlacement:function(error,element) {  
			element.parent().find(".verror").html(error);
		},
		rules:{
			"user.username":{
				required:true,
				rangelength: [4, 20],
				remote: {
					url: base + "oauth/user/check_username.action", 
					type: "POST", 
					data: {"user.id": ($("#user_id").val()), "user.username": ($("#user_username").val())}
				}
			},
			"user.realName":{
				required:true,
				rangelength: [2, 20]
			},
			"user.password":{
				required:true,
				rangelength: [6, 20]
			},
			"repassword":{
				required:true,
				rangelength: [6, 20], 
				equalTo: "#user_password"
			},
			"user.telephone":{
				isphone:true,
				rangelength: [7, 20],
				remote: {
					url: base + "oauth/user/check_telephone.action", 
					type: "POST", 
					data: {"user.id": ($("#user_id").val()), "user.telephone": ($("#user_telephone").val())}
				}
			},
			"user.email":{
				email:true,
				remote: {
					url: base + "oauth/user/check_email.action", 
					type: "POST", 
					data: {"user.id": ($("#user_id").val()), "user.email": ($("#user_email").val())}
				}
			}
		},
		messages:{
			"user.username": {
				required: "请输入登录名称", 
				rangelength:"长度不能少于{0}和大于{1}个字符",
				remote: "该名称已被使用"
			},
			"user.realName": {
				required: "请输入真实姓名",
				rangelength: "长度不能少于{0}和大于{1}个字符"
			},
			"user.password":{
				required: "请输入登录密码",
				rangelength: "长度不能少于{0}和大于{1}个字符"
			},
			"repassword": {
				required: "请输入确认密码", 
				rangelength:"长度不能少于{0}和大与{1}个字符", 
			    equalTo: "两次输入密码不一致"
			},
			"user.telephone": {
				isphone:" 电话号码格式不正确",
				rangelength:" 长度不能少于{0}和大于{1}个字符",
				remote: " 该电话号码已被使用"
			}, 
			"user.email": {
				email:" 请输入正确格式的电子邮件",
				remote: " 该邮箱已被使用"
			} 
		}
	});
});